home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Modules / waste / wastescan.py < prev    next >
Encoding:
Python Source  |  1996-08-06  |  2.4 KB  |  87 lines  |  [TEXT/Pyth]

  1. # Scan an Apple header file, generating a Python file of generator calls.
  2.  
  3. import addpack
  4. addpack.addpack(':tools:bgen:bgen')
  5. from scantools import Scanner
  6. from bgenlocations import TOOLBOXDIR
  7.  
  8. WASTEDIR=":::::Waste 1.2 distribution:"
  9.  
  10. OBJECT = "TEHandle"
  11. SHORT = "waste"
  12. OBJECT = "WEReference"
  13. OBJECT2 = "WEObjectReference"
  14.  
  15. def main():
  16.     input = WASTEDIR + "WASTE C/C++ Headers:WASTE.h"
  17.     output = SHORT + "gen.py"
  18.     defsoutput = TOOLBOXDIR + "WASTEconst.py"
  19.     scanner = MyScanner(input, output, defsoutput)
  20.     scanner.scan()
  21. ##    scanner.gentypetest(SHORT+"typetest.py")
  22.     scanner.close()
  23.     print "=== Done scanning and generating, now importing the generated code... ==="
  24.     exec "import " + SHORT + "support"
  25.     print "=== Done.  It's up to you to compile it now! ==="
  26.  
  27. class MyScanner(Scanner):
  28.  
  29.     def destination(self, type, name, arglist):
  30.         classname = "Function"
  31.         listname = "functions"
  32.         if arglist:
  33.             t, n, m = arglist[-1]
  34.             # This is non-functional today
  35.             if t == OBJECT and m == "InMode":
  36.                 classname = "Method"
  37.                 listname = "methods"
  38.             else:
  39.                 t, n, m = arglist[0]
  40.                 if t == OBJECT2 and m == "InMode":
  41.                     classname = "Method2"
  42.                     listname = "methods2"
  43.         return classname, listname
  44.  
  45.     def makeblacklistnames(self):
  46.         return [
  47.             "WEDispose",
  48.             "WESetInfo", # Argument type unknown...
  49.             "WEGetInfo",
  50.             "WEVersion", # Unfortunately...
  51.             ]
  52.  
  53.     def makeblacklisttypes(self):
  54.         return [
  55.             "DragReference",    # For now...
  56.             "UniversalProcPtr",
  57.             ]
  58.  
  59.     def makerepairinstructions(self):
  60.         return [
  61.             ([("void_ptr", "*", "InMode"), ("SInt32", "*", "InMode")],
  62.              [("InBuffer", "*", "*")]),
  63.  
  64.             # WEContinuousStyle
  65.             ([("WEStyleMode", "mode", "OutMode"), ("TextStyle", "ts", "OutMode")],
  66.              [("WEStyleMode", "mode", "InOutMode"), ("TextStyle", "ts", "OutMode")]),
  67.              
  68.             # WECopyRange
  69.             ([('Handle', 'hText', 'InMode'), ('StScrpHandle', 'hStyles', 'InMode'),
  70.                 ('WESoupHandle', 'hSoup', 'InMode')],
  71.              [('OptHandle', 'hText', 'InMode'), ('OptStScrpHandle', 'hStyles', 'InMode'),
  72.                 ('OptSoupHandle', 'hSoup', 'InMode')]),
  73.              
  74.             # WEInsert
  75.             ([('StScrpHandle', 'hStyles', 'InMode'), ('WESoupHandle', 'hSoup', 'InMode')],
  76.              [('OptStScrpHandle', 'hStyles', 'InMode'), ('OptSoupHandle', 'hSoup', 'InMode')]),
  77.              
  78.             # WEGetObjectOwner
  79.             ("WEGetObjectOwner",
  80.              [('WEReference', '*', 'ReturnMode')],
  81.              [('ExistingWEReference', '*', 'ReturnMode')])
  82.  
  83.             ]
  84.             
  85. if __name__ == "__main__":
  86.     main()
  87.